package com.afd.ozblip.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.afd.ozblip.activity.R;
import com.afd.ozblip.entity.UserSignDetialEntity;
import com.afd.ozblip.util.CollectionUtil;
import com.afd.ozblip.util.StringUtil;

public class UserSignListAdapter extends BaseAdapter {

	public List<UserSignDetialEntity> dataList;
	private LayoutInflater inflater;
	private Context context;

	public UserSignListAdapter(Context paramContext) {
		context = paramContext;
		this.dataList = new ArrayList<UserSignDetialEntity>();
		this.inflater = LayoutInflater.from(context);
	}

	/**
	 * 获取列表条数
	 */
	@Override
	public int getCount() {
		if (CollectionUtil.UnNullAndZero(this.dataList)) {
			return this.dataList.size();
		} else {
			return 0;
		}

	}

	@Override
	public Object getItem(int paramInt) {
		if (CollectionUtil.UnNullAndZero(this.dataList)) {
			return this.dataList.get(paramInt);
		} else {
			return null;
		}
	}

	@Override
	public long getItemId(int paramInt) {
		return paramInt;
	}

	@Override
	public View getView(int position, View paramView, ViewGroup paramViewGroup) {
		try {
			UserSignDetailVH detailVH = null;
			if (paramView == null) {
				detailVH = new UserSignDetailVH();
				paramView = this.inflater.inflate(
						R.layout.user_sign_detail_item, null);

				detailVH.businessNameTv = (TextView) paramView
						.findViewById(R.id.tv_user_sign_detail_item_businessName);
				detailVH.signTimeTv = (TextView) paramView
						.findViewById(R.id.tv_user_sign_detail_item_signTime);
				paramView.setTag(detailVH);
			} else {
				detailVH = (UserSignDetailVH) paramView.getTag();
			}

			UserSignDetialEntity dish = this.dataList.get(position);
			if (dish != null) {
				// 商家名称
				String businessName = dish.getSellerName();
				if (!StringUtil.isNullOrEmpty(businessName)) {
					detailVH.businessNameTv.setText(businessName);
				}
				// 签到时间
				String signTime = dish.getSginDate();
				signTime = StringUtil.getFormatData(signTime);
				if (!StringUtil.isNullOrEmpty(signTime)) {
					detailVH.signTimeTv.setText(signTime);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return paramView;
	}

	/**
	 * 添加多项
	 */
	public void addItems(List<UserSignDetialEntity> commentList) {
		this.dataList.addAll(commentList);
	}

	/**
	 * 清除所有项
	 */
	public void removeAllItem() {
		this.dataList.clear();
	}

	class UserSignDetailVH {
		TextView businessNameTv;
		TextView signTimeTv;
	}
}
